using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;
using Miris.HumanMilkAnalyser.DataModel;

namespace Miris.HumanMilkAnalyser.Repository.EntityFramework.Mapping
{
    public class AnalysisResultMap : EntityTypeConfiguration<AnalysisResult>
    {
        public AnalysisResultMap()
        {
            // Primary Key
            this.HasKey(t => t.SampleNumber);

            // Properties
            this.Property(t => t.SampleNumber)
                .IsRequired()
                .HasMaxLength(50);

            this.Property(t => t.PatientNumber)
                .IsRequired()
                .HasMaxLength(50);

            this.Property(t => t.AttachedDiagnosticMessage)
                .HasMaxLength(50);

            // Table & Column Mappings
            this.ToTable("AnalysisResult");
            this.Property(t => t.SampleNumber).HasColumnName("SampleNumber");
            this.Property(t => t.PatientNumber).HasColumnName("PatientNumber");
            this.Property(t => t.SampleType).HasColumnName("SampleType");
            this.Property(t => t.SampleStageType).HasColumnName("SampleStageType");
            this.Property(t => t.TestDate).HasColumnName("TestDate");
            this.Property(t => t.Fat).HasColumnName("Fat");
            this.Property(t => t.CrudeProtein).HasColumnName("CrudeProtein");
            this.Property(t => t.Carbohydrate).HasColumnName("Carbohydrate");
            this.Property(t => t.TS).HasColumnName("TS");
            this.Property(t => t.Energy).HasColumnName("Energy");
            this.Property(t => t.TrueProtein).HasColumnName("TrueProtein");
            this.Property(t => t.AttachedDiagnosticMessage).HasColumnName("AttachedDiagnosticMessage");

            // Relationships
            this.HasRequired(t => t.Patient)
                .WithMany(t => t.AnalysisResults)
                .HasForeignKey(d => d.PatientNumber);

        }
    }
}
